package com.fs.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fs.mapper.UserMapper;
import com.fs.pojo.User;
import com.fs.service.UserService;
import com.fs.vo.UserVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author hua
 * @version 1.0
 * @title CustomerServiceImpl
 * @description 用户服务实现类
 * @create 2024/2/28 15:08
 */
@Service("UserService")
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;

    /**
     * 根据用户名与密码验证登录
     * @param userVO 用户名与密码的一个对象
     * @return 用户
     */
    @Override
    public User login(UserVO userVO) {
        LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(User::getUsername, userVO.getUsername())
                .eq(User::getPassword, userVO.getPassword());
        return userMapper.selectOne(queryWrapper);
    }

    /**
     * 注册用户
     * @param user 用户
     * @return 注册数
     */
    @Override
    public int register(User user) {
        return userMapper.insert(user);
    }

}

